home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / misc / identify / identify_dev / examples / expansionmui.c < prev    next >
C/C++ Source or Header  |  1999-05-14  |  8KB  |  224 lines

  1. /*********************************************************************
  2. **                                                                  **
  3. **                    E X P A N S I O N M U I                       **
  4. **                                                                  **
  5. ** A small example for implementing identify in MUI applications.   **
  6. ** Compiles with SAS/C. On other C compilers, some small modifica-  **
  7. ** tions will be required regarding the __asm interface. See the    **
  8. ** manual of your C compiler for further details.                   **
  9. **                                                                  **
  10. *********************************************************************/
  11. /*
  12. **        (C) 1997 by Richard Körber -- All Rights Reserved
  13. */
  14.  
  15. #include <clib/alib_protos.h>
  16. #include <clib/exec_protos.h>
  17. #include <clib/expansion_protos.h>
  18. #include <clib/muimaster_protos.h>
  19. #include <clib/identify_protos.h>
  20. #include <pragmas/exec_pragmas.h>
  21. #include <pragmas/expansion_pragmas.h>
  22. #include <pragmas/muimaster_pragmas.h>
  23. #include <pragmas/identify_pragmas.h>
  24.  
  25. #include <stdio.h>
  26. #include <string.h>
  27.  
  28. #include <exec/memory.h>
  29. #include <libraries/identify.h>
  30. #include <libraries/mui.h>
  31. #include <libraries/configregs.h>
  32. #include <libraries/configvars.h>
  33.  
  34. #define MAKE_ID(a,b,c,d)        \
  35.         ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  36.  
  37. struct Library *MUIMasterBase;          // Library bases
  38. struct Library *ExpansionBase;
  39. struct Library *IdentifyBase;
  40.  
  41. /*------------------------------------------------------------------**
  42. **  ConstructFunc         -- Expansion list constructor hook
  43. */
  44. __saveds __asm APTR ConstructFunc
  45. (
  46.   register __a1 struct ConfigDev *cd
  47. )
  48. {
  49.   struct ConfigDev *newcd;
  50.  
  51.   newcd = AllocVec(sizeof(struct ConfigDev),MEMF_PUBLIC);
  52.   if(newcd)
  53.     CopyMem(cd,newcd,sizeof(struct ConfigDev));
  54.   return(newcd);
  55. }
  56.  
  57. /*------------------------------------------------------------------**
  58. **  DisplayFunc           -- Expansion list display hook
  59. */
  60. __saveds __asm LONG DisplayFunc
  61. (
  62.   register __a2 char **array,
  63.   register __a1 struct ConfigDev *cd
  64. )
  65. {
  66.   static char buf_nr[5];
  67.   static char buf_address[12];
  68.   static char buf_size[6];
  69.   static char buf_id[10];
  70.   static char buf_manuf[IDENTIFYBUFLEN];
  71.   static char buf_product[IDENTIFYBUFLEN];
  72.   static char buf_class[IDENTIFYBUFLEN];
  73.  
  74.   if(cd)                                  // Show the contents
  75.   {
  76.     ULONG size = cd->cd_BoardSize>>10;
  77.     ULONG unit = 'K';
  78.  
  79.     if(size>=1024)
  80.     {
  81.       unit = 'M';
  82.       size >>= 10;
  83.     }
  84.  
  85.     sprintf(buf_nr,"%ld",array[-1]+1);                // Get the entry number
  86.     sprintf(buf_address,"%08lx",cd->cd_BoardAddr);    // board address
  87.     sprintf(buf_size,"%3ld%lc",size,unit);            // board size
  88.     sprintf(buf_id,"%04lx:%02lx",cd->cd_Rom.er_Manufacturer,cd->cd_Rom.er_Product);
  89.  
  90.     IdExpansionTags(                      // Identify the expansion board
  91.       IDTAG_ConfigDev, cd,
  92.       IDTAG_ManufStr , buf_manuf,
  93.       IDTAG_ProdStr  , buf_product,
  94.       IDTAG_ClassStr , buf_class,
  95.       TAG_DONE
  96.     );
  97.  
  98.     *array++ = buf_nr;
  99.     *array++ = buf_address;
  100.     *array++ = buf_size;
  101.     *array++ = buf_id;
  102.     *array++ = buf_manuf;
  103.     *array++ = buf_product;
  104.     *array   = buf_class;
  105.   }
  106.   else                                      // Show the title line
  107.   {
  108.     *array++ = "\33b\33cNr.";
  109.     *array++ = "\33b\33cAddress";
  110.     *array++ = "\33b\33cSize";
  111.     *array++ = "\33b\33cID";
  112.     *array++ = "\33b\33cManufacturer";
  113.     *array++ = "\33b\33cProduct";
  114.     *array   = "\33b\33cClass";
  115.   }
  116.   return(0);
  117. }
  118.  
  119. /*------------------------------------------------------------------**
  120. **  DestructFunc          -- Expansion list destructor hook
  121. */
  122. __saveds __asm void DestructFunc
  123. (
  124.   register __a1 struct ConfigDev *cd
  125. )
  126. {
  127.   if(cd) FreeVec(cd);
  128. }
  129.  
  130. /*------------------------------------------------------------------**
  131. **  main                  -- MAIN PART
  132. */
  133. int main(void)
  134. {
  135.   ULONG sigs=0;                         // Signal bits
  136.   const struct Hook ConstructHook = {{NULL,NULL},(void *)ConstructFunc,NULL,NULL};
  137.   const struct Hook DisplayHook   = {{NULL,NULL},(void *)DisplayFunc  ,NULL,NULL};
  138.   const struct Hook DestructHook  = {{NULL,NULL},(void *)DestructFunc ,NULL,NULL};
  139.   Object *app;                          // Application object
  140.   Object *window;                       // Window object
  141.   Object *LV_explist;                   // Expansion listview object
  142.   struct ConfigDev *cd = NULL;          // ConfigDev traverse pointer
  143.  
  144.   if(IdentifyBase = OpenLibrary("identify.library",5))
  145.   {
  146.     if(ExpansionBase = OpenLibrary("expansion.library",36))
  147.     {
  148.       if(MUIMasterBase = OpenLibrary("muimaster.library",11))
  149.       {
  150.         app = ApplicationObject,            // Create the application
  151.           MUIA_Application_Title        , "Expansions",
  152.           MUIA_Application_Version      , "$VER: Expansions V1.1 (16.4.97)",
  153.           MUIA_Application_Copyright    , "© 1997 by Richard Körber",
  154.           MUIA_Application_Author       , "Richard Körber",
  155.           MUIA_Application_Description  , "A small identify.library example",
  156.           MUIA_Application_Base         , "EXPANSIONS",
  157.           MUIA_Application_Window       , window = WindowObject,
  158.             MUIA_Window_Title           , "Expansions Demo",
  159.             MUIA_Window_ID              , MAKE_ID('E','X','P','D'),
  160.             WindowContents, VGroup,
  161.               Child, TextObject,
  162.                 MUIA_Frame        , MUIV_Frame_Text,
  163.                 MUIA_Background   , MUII_TextBack,
  164.                 MUIA_Text_Contents, "\33cA small example how to use\nidentify.library with MUI.",
  165.               End,
  166.               Child, LV_explist = ListviewObject,
  167.                 MUIA_Listview_Input , FALSE,
  168.                 MUIA_Listview_List  , ListObject,
  169.                   MUIA_Frame              , MUIV_Frame_ReadList,
  170.                   MUIA_List_ConstructHook , &ConstructHook,
  171.                   MUIA_List_DisplayHook   , &DisplayHook,
  172.                   MUIA_List_DestructHook  , &DestructHook,
  173.                   MUIA_List_Title         , TRUE,
  174.                   MUIA_List_Format        , "P=\33r BAR,,P=\33r,BAR,D=6,P=\33c D=6,P=\33r",
  175.                 End,
  176.               End,
  177.               Child, TextObject,
  178.                 MUIA_Frame        , MUIV_Frame_Text,
  179.                 MUIA_Background   , MUII_TextBack,
  180.                 MUIA_Text_Contents, "\33cPlease send the description of all unknown boards\nto Richard Körber <shred@chessy.aworld.de>!",
  181.               End,
  182.             End,
  183.           End,
  184.         End;
  185.  
  186.         if(app)
  187.         {
  188.            // Close gadget notification
  189.           DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  190.                    app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  191.  
  192.            // Fill the expansion list
  193.           set(LV_explist,MUIA_List_Quiet,TRUE);   // Do a quick update
  194.           while(cd = FindConfigDev(cd,-1,-1))
  195.           {
  196.             DoMethod(LV_explist,MUIM_List_InsertSingle,cd,MUIV_List_Insert_Bottom);
  197.           }
  198.           set(LV_explist,MUIA_List_Quiet,FALSE);  // Now, display the list
  199.  
  200.           set(window,MUIA_Window_Open,TRUE);
  201.  
  202.            // Main Loop
  203.           while(DoMethod(app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
  204.           {
  205.             if(sigs)                        // Wait for MUI signals to occur
  206.             {
  207.               sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  208.               if(sigs & SIGBREAKF_CTRL_C) break;    // Aborted
  209.             }
  210.           }
  211.           MUI_DisposeObject(app);           // dispose the application
  212.         }
  213.         CloseLibrary(MUIMasterBase);
  214.       }
  215.       CloseLibrary(ExpansionBase);
  216.     }
  217.     CloseLibrary(IdentifyBase);
  218.   }
  219.   return 0;                             // return code 0
  220. }
  221.  
  222. /********************************************************************/
  223.  
  224.